package com.up4years.dataapi.controller;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.json.MappingJacksonJsonView;

import com.up4years.controller.base.BaseController;
import com.up4years.dataapi.entity.base.Page;
import com.up4years.dataapi.service.system.BalanceRecordService;
import com.up4years.utils.ParamUtils;
import com.up4years.utils.ValidUtil;
@Controller
@RequestMapping("/balance")
public class BalanceRecordController extends BaseController {
	@Autowired
	private BalanceRecordService balanceRecordService;
	@RequestMapping(value="/list.htm",method=RequestMethod.POST)
	public ModelAndView list(String true_name,String mobile,String id_card,String create_time,HttpServletRequest request){
/*		if(StringUtils.isBlank(true_name)&&StringUtils.isBlank(mobile)&&StringUtils.isBlank(id_card)&&StringUtils.isBlank(create_time)){
			return new ModelAndView(new MappingJacksonJsonView(),this.getFailResult("未指定查询参数"));
		}*/
		Map<String,Object> parameters = ParamUtils.convert2Map(request);
		if(StringUtils.isNotBlank((String)parameters.get("mobile"))&&!ValidUtil.validPhone((String)parameters.get("mobile"))){
			return new ModelAndView(new MappingJacksonJsonView(),this.getFailResult("手机号码格式错误！"));
		}
		if(StringUtils.isNotBlank((String)parameters.get("id_card"))&&!ValidUtil.validIdentityCard((String)parameters.get("id_card"))){
			return new ModelAndView(new MappingJacksonJsonView(),this.getFailResult("身份证号码格式错误！"));
		}
 		Page<Map<String,Object>> page = this.getPage(request);
		page = this.balanceRecordService.pageList(page, parameters);
		return new ModelAndView(new MappingJacksonJsonView(),this.getSuccessResult(page));
	}

 }	
